<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="ihis.model.*" %>
<%@ page import="ihis.core.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@page import="ihis.tms.client.IHISTMSClient"%>

<%@ include file="filter.jsp" %>
    
<%	
	Date reportDat = null;
	if (!IHISUtil.isEmpty(startDate)) {
		sdf = new SimpleDateFormat("yyyy-MM-dd");
		reportDat = sdf.parse(startDate);
	}else if (!IHISUtil.isEmpty(endDate)) {
		sdf = new SimpleDateFormat("yyyy-MM-dd");
		reportDat = sdf.parse(endDate);
	}else if(!IHISUtil.isEmpty(reportDate)){
		sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		reportDat = sdf.parse(reportDate);
	}
	sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	filter.setReportDate(sdf.format(GeneralFilter.generateToDate(reportDat, filter.getPeriodType(), false)));
	reportDate = filter.getReportDate();
	PerformanceReport report = (PerformanceReport) core.getReport(IHISConstants.REPORT_PERFORMANCE, filter);
	List<Performance> performances = report.getPerformanceList();	
%>


<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Schedule Performance Report</title>
    <link rel="stylesheet" href="script/jquery.mobile-1.0a4.1.min.css"/>
    <link rel="stylesheet" href="script/ihis.css"/>
    <script src="script/jquery-1.6.min.js"></script>
    <script src="script/ihis.schedule.js"></script>
    <script src="script/jquery.mobile-1.0a4.1.min.js"></script>
</head>

<body>
	<div id="performancePage" data-role="page" data-theme="b">
		<div data-role="header" data-position="fixed">
			<a href="#" data-icon="back" data-role="button" id="backButton">Back</a>
			<h1><%= IHISConstants.OWNERTYPE_PERSON == Integer.parseInt(ownerType) ? userName + "님의 성과" : "조직 성과" %></h1>
			<a href="#" data-icon="home" data-role="button" id="homeButton">Home</a>
		</div>

		<div data-role="content"  data-theme="a">
			<ul data-role="listview" data-inset="true" data-filter="true">
<%
	if(performances != null){
		for(Performance p : performances){
			String tempUserName = null;
			if(filter.getOwnerType() == IHISConstants.OWNERTYPE_PERSON)
				tempUserName = tms.getUserName(p.getOwnerId());
			else if(filter.getOwnerType() == IHISConstants.OWNERTYPE_TEAM)
				tempUserName = tms.getTeamName(p.getTeamId());
			String tempProjectName = tms.getProjectName(p.getProjectId());
			StringBuilder result = new StringBuilder();
			result.append("M(").append(p.getManageability()).append(") ")
				.append("A(").append(p.getAttitude()).append("), ")
				.append("R(").append(p.getResponsibility()).append("), ")
				.append("C(").append(p.getContribution()).append(")");
%>	
				<li>
					<h3><%= tempUserName %></h3>
					<p><%= IHISUtil.dateToStr(p.getReportDate()) + " / " + tempProjectName %></p>
					<p><%= result.toString() %>
				</li>
<%
		}
	}
%>
			</ul>
			<%
				StringBuilder sb = new StringBuilder("Filter :<br/>");
				if(!IHISUtil.isEmpty(startDate)){
					sb.append(startDate).append(" ");
				}
				if(!IHISUtil.isEmpty(endDate)){
					sb.append("~").append(endDate).append(" ");
				}
				if(!IHISUtil.isEmpty(user)){
					sb.append("/ ").append(userName).append("(").append(user).append(") " );
				}
				if(!IHISUtil.isEmpty(team)){
					sb.append("/ ").append(teamName).append(" ");
				}
				if(!IHISUtil.isEmpty(project)){
					sb.append("/ ").append(projectName).append(" ");
				}
				
			%>
			<h5><%= sb.toString() %><br/>
			Legend :<br/>M(Manageability), A(Attitude), R(Responsibility), C(Contribution)</h5>
		</div> 

	<script type="text/javascript">
    	$(function(){
    		$("#searchButton").bind("click", function(){
				<% 
					StringBuilder url = new StringBuilder("searchSchedule.jsp?filterFor=performance");
					url.append("&periodType=").append("" + filter.getPeriodType());
					url.append("&ownerType=").append("" + filter.getOwnerType());

					if(filter.getStartDate() != null){
						url.append("&").append("startDate=").append(new SimpleDateFormat("yyyy-MM-dd").format(filter.getStartDate()));
					}
					if(filter.getEndDate() != null){
						url.append("&").append("endDate=").append(new SimpleDateFormat("yyyy-MM-dd").format(filter.getEndDate()));
					}
					if(!IHISUtil.isEmpty(filter.getUserId())){
						url.append("&").append("user=").append(filter.getUserId());
					}
					if(!IHISUtil.isEmpty(filter.getProjectId())){
						url.append("&").append("project=").append(filter.getProjectId());
					}
					if(!IHISUtil.isEmpty(filter.getTeamId())){
						url.append("&").append("team=").append(filter.getTeamId());
					}
				%>
				var url = "<%= url %>";
				document.location = url;
    		});
    	});
    	// 1. page 로 지정된 ID 값,  2.효과 3. 방향 :  false(>), true(<)
    </script>		
		
		<div data-role="footer" data-position="fixed">
			<a href="" id="searchButton" data-icon="check"  data-transition="slideup">Search</a>
			<a href="javascript:window.location.reload(true)" data-icon="refresh" data-rel="refresh" data-transition="flip">Refresh</a>
		</div>
		
	</div>
	
	<!-- 검색 정보를 저장해둔다. : Task 목록을 위해 사용 -->
	<div>
		<form action="#" method="post" name="filterForm">
			<input type="hidden" name="startDate" value="<%= startDate%>"/>
			<input type="hidden" name="endDate" value="<%= endDate%>"/>
			<input type="hidden" name="periodType" value="<%= periodType%>"/>
			<input type="hidden" name="user" value="<%= user%>"/>
			<input type="hidden" name="team" value="<%= team%>"/>
			<input type="hidden" name="ownerType" value="<%= ownerType%>"/>
			<input type="hidden" name="taskType" value=""/>
		</form>
	</div>
</body>
</html>